#include <iostream>
#include <vector>
using namespace std;
const int N = 15;

int n, k;
vector<int> path;
bool s[N];

void dfs()
{
    if(path.size() == k)
    {
        for(auto e : path)
        {
            cout << e << " ";
        }
        cout << endl;
        return;
    }

    for(int i = 1; i <= n; i++)
    {
        if(s[i]) continue;
        path.push_back(i);
        s[i] = true;
        dfs();
        path.pop_back();
        s[i] = false;
    }
}

int main()
{
    cin >> n >> k;

    dfs();
    return 0;
}
